package Exercise;

/**
 * Description：
 * Author: zhangc
 * Date：2017/9/28 10:36
 */
public class SubString {

    public static void main(String[] args) {
        String str = "zhangchao";
        String s = "chao";
        String sub = "char";
        System.out.println(containsStr(str, s));
        System.out.println(containsStr(str, sub));
    }

    public static boolean containsStr(String str, String sub) {
        int len = 0;
        for (int i = 0; i < str.length(); i++) {
            len = 0;
            for (int j = 0; j < sub.length(); j++) {
                if (i + j < str.length() && sub.charAt(j) == str.charAt(i + j)) {
                    len++;
                    if (j == sub.length() - 1)
                        return true;
                } else
                    break;
            }
        }
        return len == sub.length();
    }

}
